package com.senyint.hip.fhir.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * *******description*******
 * <p>
 * *************************
 *
 * @author ChenPan
 * @date 2018/10/30 11:12
 */
public class DateUtils {

    public static Date date(String dateString) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    
    public static Date string2Date(String date) {
    	SimpleDateFormat format;
		Date d = null;
		if(date.indexOf("+")!=-1) {
			  date=date.substring(0,date.indexOf("+"));
			  date = date.replace("T", " ");
		  }
		
		if(date.contains("T")) {
			date = date.replace("Z", " UTC");
 			  format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
			  
			  try {
				d =   format.parse(date);
			} catch (ParseException e) {
				
				e.printStackTrace();
			}
		}else {
			 format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			  try {
				d =   format.parse(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return d;
    }
}
